<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author konda
 */
class login extends CI_Controller{
    //put your code here
    
    public function __construct() {
        parent::__construct();

         parent::__construct();
        
         //library
         $this->load->library(array('table','pagination','form_validation'));
         
         //helper
         $this->load->helper(array('form','url'));
         //model
         $this->load->model('m_login');
   

    }
    
    public function Index()
    {

      $data['title']="Login";

      $this->load->view('template/header.php',$data);
      $this->load->view('v_login.php');
      $this->load->view('template/footer.php');
   

    }


   /*
    ** function login process 
    ** for user and password
    **
    */
   public function process()
   {
     

     $user=$_POST['user'];
     $pass=$_POST['pass'];

     $result=$this->m_login->process($user,$pass);

       if(!$result)
        {

         $result=array();
         $result['result']="ERROR";
         $result['message']="Usuario o Password Incorrecto";
         echo json_encode($result);
        }
        else
        {
      
         $result=array();
         $result['result']="OK";
         $result['message']="Redireccionando";
         $result['redirect']="departamento";
         echo json_encode($result);
          
         //save the session 
          $data=array();
          $data['user']=$user;
          $data['login_state']=TRUE;
          $this->session->set_userdata($data);


         //redirect("/departamento");
        

        }

    
  }
     
   


}

?>
